package com.qire.manhua.model.vo;

import android.graphics.Rect;

import com.qire.common.basic.ObjectUtil;
import com.qire.common.collect.ArrayUtil;
import com.qire.common.support.base.BaseVO;
import com.qire.manhua.model.entity.ComicBookEntity;
import com.qire.manhua.model.entity.ComicBookEntity.ChaptersInfo;

public class ComicReadFinishPushVO extends BaseVO {

    public ComicLastInfoVO      srcBookInfo;    //: {},
    public ComicSimpleInfoVO    bookInfo;       //: {},
    public ChapterInfoVO        chapterInfo;    //: {}

    public class ComicLastInfoVO {
        public String   book_name;          //: "狂女重生：纨绔七皇妃",
        public int      end_state;          //: 0,
        public String   update_cycle;       //: "每周二、五更新"
    }

    public class ComicSimpleInfoVO {
        public int          id;                 //: 10775,
        public String       book_name;          //: "女帝的后宫",
        public String       book_cover;         //: "https://p.qiremanhua.com/uploads/book/201909/5d78a12ca374d.jpg?x-oss-process=image/quality,q_90/format,webp",
        public ExtraInfoVO  tj;                 //: {},
        public int          shelf;              //: 0,
        public int          end_state;          //: 0,
        public int          chapter_px;         //: 118

        public class ExtraInfoVO {
            public int like_cnt;                //: 72390
        }

        public ComicBookEntity toComicBookEntity() {
            return new ComicBookEntity(id, book_name);
        }
    }

    public class ChapterInfoVO {
        public int          id;                 //: 59234,
        public int          next_id;            //: 59235,
        public String       chapter_name;       //: "预告",
        public String[]     content;            //: [],
        public SizeVO[]     whs;                //: [],
        public int          content_imgs_count; //: 21
        public class SizeVO {
            public int w;
            public int h;
        }

        public void fillComic(ComicBookEntity comicBookEntity) {
            if(ObjectUtil.nonNull(comicBookEntity) && ArrayUtil.notEmpty(content)) {
                ChaptersInfo chaptersInfo = comicBookEntity.chaptersReading(id);

                int pictureRectSize = whs != null ? whs.length : 0;
                Rect[] pictureRectArray = new Rect[pictureRectSize];
                for(int index = 0; index < pictureRectSize; index++) {
                    pictureRectArray[index] = new Rect(0, 0, whs[index].w, whs[index].h);
                }

                chaptersInfo.loadAllPictureResource(content, pictureRectArray);
            }
        }
    }

}
